package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqGeneralValueResult;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class ChangeDeviceIdReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // *WT,866248050395985,V4,CHOOSEID,095517,0,095519,A,2250.2256,N,11391.6190,E,0.18,162,030621,FFFFDFFF#
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber = split[4];
        String idParam = split[5];//0:IMEID 1:ICCID 如果是iccid来标识设备，后面就填写imeid，如果是imeid来标识设备，后面就填写iccid
        String time = split[6];//时间（时分秒）
        String lat = split[8];
        String lng = split[10];
        String speed = split[12];
        String orientation = split[13];
        String date = split[14];
        String deviceStatus = split[15];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        MqGeneralValueResult mqGeneralValueResult = new MqGeneralValueResult();
        mqGeneralValueResult.setCommandNumber(commandNumber);
        mqGeneralValueResult.setDeviceDate(date);
        mqGeneralValueResult.setDeviceStatus(deviceStatus);
        mqGeneralValueResult.setDeviceTime(time);
        mqGeneralValueResult.setMqLocationData(mqLocationData);
        mqGeneralValueResult.setValue(idParam);
        InjectFeignService.getIrmFeignClientService().changeIdResponse(mqGeneralValueResult);
        return imei;
    }
}
